

//向其他服务提示我已经登录过了
function loginCookie(){
	var username = $("#username").val();
	var password = $("#password").val();	
	for(var i=8071;i<8076;i++){
        $.ajax({
        	type:"post",
        	url:"http://127.0.0.1:"+i+"/login",
        	xhrFields:{withCredentials: true},
        	crossDomain: true,
        	dataType:"json",
        	data:{"username":0,"password":0,"status":"false"},
        	success:function(msg){
        		if(msg != 0){
        			//$(location).attr('href', 'show.html');
        		}else{
        			alert("登录失败状态码："+msg);
        			//登录失败还是跳转到登录页面
        		}
        		
        	} 
        })
   	}
}


//是否免登陆状态赋值
var status = false;
function mianD(){status = true;}

//登录操作
function loginInsert(){
	//获取账号 密码 状态
	//username password status
	var username = $("#username").val();
	var password = $("#password").val();
	//alert("数据："+username+"  "+password+"  "+status);
	$.ajax({
	    type:"post",
	    async: true, //是否异步
	    url:"http://127.0.0.1:8075/login",      // 这里是提交到什么地方的url
	    xhrFields:{withCredentials: true},
	    crossDomain: true,
	    dataType: "json", //跨域json请求一定是jsonp
	    data:{"username":username,"password":password,"status":status},// 这里把表单里面的数据放在这里传到后台
	    success:function(data){
	        // 调用回调函数
	        //alert("登录成功后返回的结果"+data)
	        if(data != 0){
	        	//alert("登录成功！");
				for(var i=8071;i<8076;i++){
			        $.ajax({
			        	type:"post",
			        	url:"http://127.0.0.1:"+i+"/login",
			        	xhrFields:{withCredentials: true},
			        	crossDomain: true,
			        	dataType:"json",
			        	data:{"username":username,"password":password,"status":status},
			        	success:function(msg){
			        		//alert("登录回调函数再次发请求的回调函数："+msg);
			        	} 
			        })}
				  $.ajax({//登录成功后根据账号所属的部门做相应页面的跳转
			        	type:"post",
			        	url:"http://127.0.0.1:8073/showPost",
			        	xhrFields:{withCredentials: true},
			        	crossDomain: true,
			        	dataType:"json",
			        	data:{"username":data},
			        	success:function(msg){
			        		if (msg.pname=="快递员") {
			        		$(location).attr('href', '../LH_PM/Home.html');
			        		}else if (msg.pname=="营业厅业务员"){
			        		$(location).attr('href', '../RJH_PM/Home.html');	
			        		}else if (msg.pname=="中转中心业务员"){
			        	    $(location).attr('href', '../ZZG_PM/Home.html');
			        		}else if (msg.pname=="中转中心仓库管理员"){
			        		$(location).attr('href', '../CMH_PM/Home.html');	
			        		}else if (msg.pname=="财务人员"){
			        	    $(location).attr('href', '../ZZG_PM/Home.html');
			        		}else if (msg.pname=="总经理"){
			        		$(location).attr('href', '../LH_PM/Home.html');	
			        		}else if (msg.pname=="管理员"){
			        		$(location).attr('href', '../LH_PM/Home.html');	
			        		}
			        	} 
			        })
	        }

	    },
	    complete:function(data){
	    	//alert("请求完成");
	    },
	    error:function(){
	    	alert("异常！")
	    }
	});
}


//退出登录
function logout(){
	for(var i=8071;i<8076;i++){
	    $.ajax({
	    	type:"post",
	    	async: true, //是否异步
	    	url:"http://127.0.0.1:"+i+"/logout",
	    	xhrFields:{withCredentials: true},
	    	crossDomain: true,
	    	dataType:"json",
	    	data:{"username":0,"password":0,"status":false},
	    	success:function(msg){
	    		$(location).attr('href', 'UserLogin.html');
	    	}})
    }
}




//权限测试
function quanx(){
	$.ajax({
    	type:"post",
    	async: true, //是否异步
    	url:"http://127.0.0.1:8075/test",
	    xhrFields:{withCredentials: true},
	    crossDomain: true,
    	dataType:"json",
    	success:function(msg){
    		alert("没有权限回调函数："+msg);
    	} 
    })		
		
	

}